package com.veterinaria.dao;

import java.io.Reader;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.veterinaria.bean.CreditoBean;
import com.veterinaria.services.CreditoService;

public class CreditoDAO implements CreditoService{
	
	SqlSessionFactory sqlmapper= null;{
		try {	
	   	 	Reader reader = Resources.getResourceAsReader("ConfiguracionIbatis.xml");
	   	 	sqlmapper =new  SqlSessionFactoryBuilder().build(reader);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Override
	public void grabarCredito(CreditoBean obj) throws Exception {
		// TODO Auto-generated method stub
		SqlSession session = sqlmapper.openSession();
		try {
			session.insert("creditoxml.grabarCredito",obj);
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
			session.rollback();
		}finally{ session.close();}
	}

}
